﻿# -*- coding:utf-8 -*-

from ktit.storage.categories import create_cat_tree
from django.core.urlresolvers import reverse

def category_proc(request):
    "A context processor that provides cattree & excat."

    if "expanded_catid" not in request.session:
        request.session["expanded_catid"] = [0]
    cattree = create_cat_tree(request.session["expanded_catid"])
    curcat = request.session["current_category"]

    #hp = [HISTORYPATH[i] for i in request.session["history_path"]]

    gm = ""
    if "global_message" in request.session:
        gm = request.session["global_message"]

    menu_items=(
    {'id':'1','caption':'Главная','url':reverse('ktit.storage.views.main.index'),#
                'sub_menu_items':(
                {'id':'1','caption':'sub 10','url':'',},
                {'id':'2','caption':'sub 20','url':'',},
                )},
    {'id':'2','caption':'Комплектующие','url':'',
                'sub_menu_items':(
                {'id':'1','caption':'Каталог','url':'',},
                )},
    {'id':'3','caption':'Документы','url':reverse('doc_open'),
                'sub_menu_items':(
                {'id':'1','caption':'Открытые','url':reverse('doc_open'),},
                {'id':'2','caption':'Все','url':reverse('doc_all'),},
                )},
    )
    #sub_departments  

    #print menu_items[0]['sub_menu_items'] #sub_menu_items

    return {
        'cattree': cattree,
        'currentcategory': curcat,
        #'history_path' : hp,
        'global_message' : gm,
        'menu_items':menu_items,
    }